package lvxu.service;

import lvxu.bean.*;
import lvxu.dao.SongMapper;
import lvxu.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SongService {
    @Autowired
    SongMapper songMapper;
    public void addMusic(Song song) {
        songMapper.insert(song);
    }

    public boolean selectByid(Integer musicid) {
        SongExample songExample = new SongExample();
        SongExample.Criteria criteria = songExample.createCriteria();
        criteria.andMusicidEqualTo(musicid);
        long songLists = songMapper.countByExample(songExample);
        return songLists != 0?true:false;
    }


    public void deleteById(Integer del_id,Integer state) {
        SongExample songExample = new SongExample();
        SongExample.Criteria criteria = songExample.createCriteria();
        criteria.andMusicidEqualTo(del_id);
        criteria.andStateEqualTo(state);
        songMapper.deleteByExample(songExample);
    }
    //查询所有歌曲信息   通过用户id歌曲id及状态查询该用户收藏的歌曲
    public List<Song> selectByUserIdWithState(Integer userid,Integer state) {
        SongExample songExample = new SongExample();
        SongExample.Criteria criteria = songExample.createCriteria();
        criteria.andUseridEqualTo(userid);
        criteria.andStateEqualTo(state);
        List<Song> songList = songMapper.selectByExampleWithMusic(songExample);
        System.out.println(songList);
        return songList;
    }

    public void insertSong(Song Song) {
        songMapper.insert(Song);
    }

    public void deleteSong(Integer musicid) {
        SongExample songExample = new SongExample();
        SongExample.Criteria criteria = songExample.createCriteria();
        criteria.andMusicidEqualTo(musicid);
        songMapper.deleteByExample(songExample);
    }

    public List<Song> selectByUserId(Integer userid) {
        SongExample songExample = new SongExample();
        SongExample.Criteria criteria = songExample.createCriteria();
        criteria.andUseridEqualTo(userid);
        List<Song> songs = songMapper.selectByExample(songExample);
        return songs;
    }
}
